home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / i960-tdep.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  21KB  |  647 lines

  1. /* Target-machine dependent code for the Intel 960
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.    Contributed by Intel Corporation.
  4.    examine_prologue and other parts contributed by Wind River Systems.
  5.  
  6. This file is part of GDB.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* Miscellaneous i80960-dependent routines.
  23.    Most are called from macros defined in "tm-i960.h".  */
  24.  
  25. #include <stdio.h>
  26. #include <signal.h>
  27. #include "defs.h"
  28. #include "param.h"
  29. #include "symtab.h"
  30. #include "value.h"
  31. #include "frame.h"
  32. #include "signame.h"
  33. #include "ieee-float.h"
  34.  
  35. /* Structure of i960 extended floating point format.  */
  36.  
  37. const struct ext_format ext_format_i960 = {
  38. /* tot sbyte smask expbyte manbyte */
  39.    12, 9,    0x80, 9,8,       4,0,        /* i960 */
  40. };
  41.  
  42. /* gdb960 is always running on a non-960 host.  Check its characteristics.
  43.    This routine must be called as part of gdb initialization.  */
  44.  
  45. static void
  46. check_host()
  47. {
  48.     int i;
  49.  
  50.     static struct typestruct {
  51.         int hostsize;        /* Size of type on host        */
  52.         int i960size;        /* Size of type on i960        */
  53.         char *typename;        /* Name of type, for error msg    */
  54.     } types[] = {
  55.         { sizeof(short),  2, "short" },
  56.         { sizeof(int),    4, "int" },
  57.         { sizeof(long),   4, "long" },
  58.         { sizeof(float),  4, "float" },
  59.         { sizeof(double), 8, "double" },
  60.         { sizeof(char *), 4, "pointer" },
  61.     };
  62. #define TYPELEN    (sizeof(types) / sizeof(struct typestruct))
  63.  
  64.     /* Make sure that host type sizes are same as i960
  65.      */
  66.     for ( i = 0; i < TYPELEN; i++ ){
  67.         if ( types[i].hostsize != types[i].i960size ){
  68.             printf("sizeof(%s) != %d:  PROCEED AT YOUR OWN RISK!\n",
  69.                     types[i].typename, types[i].i960size );
  70.         }
  71.  
  72.     }
  73. }
  74.  
  75. /* Examine an i960 function prologue, recording the addresses at which
  76.    registers are saved explicitly by the prologue code, and returning
  77.    the address of the first instruction after the prologue (but not
  78.    after the instruction at address LIMIT, as explained below).
  79.  
  80.    LIMIT places an upper bound on addresses of the instructions to be
  81.    examined.  If the prologue code scan reaches LIMIT, the scan is
  82.    aborted and LIMIT is returned.  This is used, when examining the
  83.    prologue for the current frame, to keep examine_prologue () from
  84.    claiming that a given register has been saved when in fact the
  85.    instruction that saves it has not yet been executed.  LIMIT is used
  86.    at other times to stop the scan when we hit code after the true
  87.    function prologue (e.g. for the first source line) which might
  88.    otherwise be mistaken for function prologue.
  89.  
  90.    The format of the function prologue matched by this routine is
  91.    derived from examination of the source to gcc960 1.21, particularly
  92.    the routine i960_function_prologue ().  A "regular expression" for
  93.    the function prologue is given below:
  94.  
  95.    (lda LRn, g14
  96.     mov g14, g[0-7]
  97.     (mov 0, g14) | (lda 0, g14))?
  98.  
  99.    (mov[qtl]? g[0-15], r[4-15])*
  100.    ((addo [1-31], sp, sp) | (lda n(sp), sp))?
  101.    (st[qtl]? g[0-15], n(fp))*
  102.  
  103.    (cmpobne 0, g14, LFn
  104.     mov sp, g14
  105.     lda 0x30(sp), sp
  106.     LFn: stq g0, (g14)
  107.     stq g4, 0x10(g14)
  108.     stq g8, 0x20(g14))?
  109.  
  110.    (st g14, n(fp))?
  111.    (mov g13,r[4-15])?
  112. */
  113.  
  114. /* Macros for extracting fields from i960 instructions.  */
  115.  
  116. #define BITMASK(pos, width) (((0x1 << (width)) - 1) << (pos))
  117. #define EXTRACT_FIELD(val, pos, width) ((val) >> (pos) & BITMASK (0, width))
  118.  
  119. #define REG_SRC1(insn)    EXTRACT_FIELD (insn, 0, 5)
  120. #define REG_SRC2(insn)    EXTRACT_FIELD (insn, 14, 5)
  121. #define REG_SRCDST(insn)  EXTRACT_FIELD (insn, 19, 5)
  122. #define MEM_SRCDST(insn)  EXTRACT_FIELD (insn, 19, 5)
  123. #define MEMA_OFFSET(insn) EXTRACT_FIELD (insn, 0, 12)
  124.  
  125. /* Fetch the instruction at ADDR, returning 0 if ADDR is beyond LIM or
  126.    is not the address of a valid instruction, the address of the next
  127.    instruction beyond ADDR otherwise.  *PWORD1 receives the first word
  128.    of the instruction, and (for two-word instructions), *PWORD2 receives
  129.    the second.  */
  130.  
  131. #define NEXT_PROLOGUE_INSN(addr, lim, pword1, pword2) \
  132.   (((addr) < (lim)) ? next_insn (addr, pword1, pword2) : 0)
  133.  
  134. static CORE_ADDR
  135. examine_prologue (ip, limit, frame_addr, fsr)
  136.      register CORE_ADDR ip;
  137.      register CORE_ADDR limit;
  138.      FRAME_ADDR frame_addr;
  139.      struct frame_saved_regs *fsr;
  140. {
  141.   register CORE_ADDR next_ip;
  142.   register int src, dst;
  143.   register unsigned int *pcode;
  144.   unsigned int insn1, insn2;
  145.   int size;
  146.   int within_leaf_prologue;
  147.   CORE_ADDR save_addr;
  148.   static unsigned int varargs_prologue_code [] =
  149.     {
  150.        0x3507a00c,    /* cmpobne 0x0, g14, LFn */
  151.        0x5cf01601,    /* mov sp, g14         */
  152.        0x8c086030,    /* lda 0x30(sp), sp     */
  153.        0xb2879000,    /* LFn: stq  g0, (g14)   */
  154.        0xb2a7a010,    /* stq g4, 0x10(g14)     */
  155.        0xb2c7a020    /* stq g8, 0x20(g14)     */
  156.     };
  157.  
  158.   /* Accept a leaf procedure prologue code fragment if present.
  159.      Note that ip might point to either the leaf or non-leaf
  160.      entry point; we look for the non-leaf entry point first:  */
  161.  
  162.   within_leaf_prologue = 0;
  163.   if ((next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2))
  164.       && ((insn1 & 0xfffff000) == 0x8cf00000         /* lda LRx, g14 (MEMA) */
  165.       || (insn1 & 0xfffffc60) == 0x8cf03000))    /* lda LRx, g14 (MEMB) */
  166.     {
  167.       within_leaf_prologue = 1;
  168.       next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn1, &insn2);
  169.     }
  170.  
  171.   /* Now look for the prologue code at a leaf entry point:  */
  172.  
  173.   if (next_ip
  174.       && (insn1 & 0xff87ffff) == 0x5c80161e         /* mov g14, gx */
  175.       && REG_SRCDST (insn1) <= G0_REGNUM + 7)
  176.     {
  177.       within_leaf_prologue = 1;
  178.       if ((next_ip = NEXT_PROLOGUE_INSN (next_ip, limit, &insn1, &insn2))
  179.       && (insn1 == 0x8cf00000                   /* lda 0, g14 */
  180.           || insn1 == 0x5cf01e00))              /* mov 0, g14 */
  181.     {
  182.       ip = next_ip;
  183.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  184.       within_leaf_prologue = 0;
  185.     }
  186.     }
  187.  
  188.   /* If something that looks like the beginning of a leaf prologue
  189.      has been seen, but the remainder of the prologue is missing, bail.
  190.      We don't know what we've got.  */
  191.  
  192.   if (within_leaf_prologue)
  193.     return (ip);
  194.       
  195.   /* Accept zero or more instances of "mov[qtl]? gx, ry", where y >= 4.
  196.      This may cause us to mistake the moving of a register
  197.      parameter to a local register for the saving of a callee-saved
  198.      register, but that can't be helped, since with the
  199.      "-fcall-saved" flag, any register can be made callee-saved.  */
  200.  
  201.   while (next_ip
  202.      && (insn1 & 0xfc802fb0) == 0x5c000610
  203.      && (dst = REG_SRCDST (insn1)) >= (R0_REGNUM + 4))
  204.     {
  205.       src = REG_SRC1 (insn1);
  206.       size = EXTRACT_FIELD (insn1, 24, 2) + 1;
  207.       save_addr = frame_addr + ((dst - R0_REGNUM) * 4);
  208.       while (size--)
  209.     {
  210.       fsr->regs[src++] = save_addr;
  211.       save_addr += 4;
  212.     }
  213.       ip = next_ip;
  214.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  215.     }
  216.  
  217.   /* Accept an optional "addo n, sp, sp" or "lda n(sp), sp".  */
  218.  
  219.   if (next_ip &&
  220.       ((insn1 & 0xffffffe0) == 0x59084800    /* addo n, sp, sp */
  221.        || (insn1 & 0xfffff000) == 0x8c086000    /* lda n(sp), sp (MEMA) */
  222.        || (insn1 & 0xfffffc60) == 0x8c087400))    /* lda n(sp), sp (MEMB) */
  223.     {
  224.       ip = next_ip;
  225.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  226.     }
  227.  
  228.   /* Accept zero or more instances of "st[qtl]? gx, n(fp)".  
  229.      This may cause us to mistake the copying of a register
  230.      parameter to the frame for the saving of a callee-saved
  231.      register, but that can't be helped, since with the
  232.      "-fcall-saved" flag, any register can be made callee-saved.
  233.      We can, however, refuse to accept a save of register g14,
  234.      since that is matched explicitly below.  */
  235.  
  236.   while (next_ip &&
  237.      ((insn1 & 0xf787f000) == 0x9287e000      /* stl? gx, n(fp) (MEMA) */
  238.       || (insn1 & 0xf787fc60) == 0x9287f400   /* stl? gx, n(fp) (MEMB) */
  239.       || (insn1 & 0xef87f000) == 0xa287e000   /* st[tq] gx, n(fp) (MEMA) */
  240.       || (insn1 & 0xef87fc60) == 0xa287f400)  /* st[tq] gx, n(fp) (MEMB) */
  241.      && ((src = MEM_SRCDST (insn1)) != G14_REGNUM))
  242.     {
  243.       save_addr = frame_addr + ((insn1 & BITMASK (12, 1))
  244.                 ? insn2 : MEMA_OFFSET (insn1));
  245.       size = (insn1 & BITMASK (29, 1)) ? ((insn1 & BITMASK (28, 1)) ? 4 : 3)
  246.                                    : ((insn1 & BITMASK (27, 1)) ? 2 : 1);
  247.       while (size--)
  248.     {
  249.       fsr->regs[src++] = save_addr;
  250.       save_addr += 4;
  251.     }
  252.       ip = next_ip;
  253.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  254.     }
  255.  
  256.   /* Accept the varargs prologue code if present.  */
  257.  
  258.   size = sizeof (varargs_prologue_code) / sizeof (int);
  259.   pcode = varargs_prologue_code;
  260.   while (size-- && next_ip && *pcode++ == insn1)
  261.     {
  262.       ip = next_ip;
  263.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  264.     }
  265.  
  266.   /* Accept an optional "st g14, n(fp)".  */
  267.  
  268.   if (next_ip &&
  269.       ((insn1 & 0xfffff000) == 0x92f7e000     /* st g14, n(fp) (MEMA) */
  270.        || (insn1 & 0xfffffc60) == 0x92f7f400))   /* st g14, n(fp) (MEMB) */
  271.     {
  272.       fsr->regs[G14_REGNUM] = frame_addr + ((insn1 & BITMASK (12, 1))
  273.                             ? insn2 : MEMA_OFFSET (insn1));
  274.       ip = next_ip;
  275.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  276.     }
  277.  
  278.   /* Accept zero or one instance of "mov g13, ry", where y >= 4.
  279.      This is saving the address where a struct should be returned.  */
  280.  
  281.   if (next_ip
  282.       && (insn1 & 0xff802fbf) == 0x5c00061d
  283.       && (dst = REG_SRCDST (insn1)) >= (R0_REGNUM + 4))
  284.     {
  285.       save_addr = frame_addr + ((dst - R0_REGNUM) * 4);
  286.       fsr->regs[G0_REGNUM+13] = save_addr;
  287.       ip = next_ip;
  288. #if 0  /* We'll need this once there is a subsequent instruction examined. */
  289.       next_ip = NEXT_PROLOGUE_INSN (ip, limit, &insn1, &insn2);
  290. #endif
  291.     }
  292.  
  293.   return (ip);
  294. }
  295.  
  296. /* Given an ip value corresponding to the start of a function,
  297.    return the ip of the first instruction after the function 
  298.    prologue.  */
  299.  
  300. CORE_ADDR
  301. skip_prologue (ip)
  302.      CORE_ADDR (ip);
  303. {
  304.   struct frame_saved_regs saved_regs_dummy;
  305.   struct symtab_and_line sal;
  306.   CORE_ADDR limit;
  307.  
  308.   sal = find_pc_line (ip, 0);
  309.   limit = (sal.end) ? sal.end : 0xffffffff;
  310.  
  311.   return (examine_prologue (ip, limit, (FRAME_ADDR) 0, &saved_regs_dummy));
  312. }
  313.  
  314. /* Put here the code to store, into a struct frame_saved_regs,
  315.    the addresses of the saved registers of frame described by FRAME_INFO.
  316.    This includes special registers such as pc and fp saved in special
  317.    ways in the stack frame.  sp is even more special:
  318.    the address we return for it IS the sp for the next frame.
  319.  
  320.    We cache the result of doing this in the frame_cache_obstack, since
  321.    it is fairly expensive.  */
  322.  
  323. void
  324. frame_find_saved_regs (fi, fsr)
  325.      struct frame_info *fi;
  326.      struct frame_saved_regs *fsr;
  327. {
  328.   register CORE_ADDR next_addr;
  329.   register CORE_ADDR *saved_regs;
  330.   register int regnum;
  331.   register struct frame_saved_regs *cache_fsr;
  332.   extern struct obstack frame_cache_obstack;
  333.   CORE_ADDR ip;
  334.   struct symtab_and_line sal;
  335.   CORE_ADDR limit;
  336.  
  337.   if (!fi->fsr)
  338.     {
  339.       cache_fsr = (struct frame_saved_regs *)
  340.           obstack_alloc (&frame_cache_obstack,
  341.                  sizeof (struct frame_saved_regs));
  342.       bzero (cache_fsr, sizeof (struct frame_saved_regs));
  343.       fi->fsr = cache_fsr;
  344.  
  345.       /* Find the start and end of the function prologue.  If the PC
  346.      is in the function prologue, we only consider the part that
  347.      has executed already.  */
  348.          
  349.       ip = get_pc_function_start (fi->pc);
  350.       sal = find_pc_line (ip, 0);
  351.       limit = (sal.end && sal.end < fi->pc) ? sal.end: fi->pc;
  352.  
  353.       examine_prologue (ip, limit, fi->frame, cache_fsr);
  354.  
  355.       /* Record the addresses at which the local registers are saved.
  356.      Strictly speaking, we should only do this for non-leaf procedures,
  357.      but no one will ever look at these values if it is a leaf procedure,
  358.      since local registers are always caller-saved.  */
  359.  
  360.       next_addr = (CORE_ADDR) fi->frame;
  361.       saved_regs = cache_fsr->regs;
  362.       for (regnum = R0_REGNUM; regnum <= R15_REGNUM; regnum++)
  363.     {
  364.       *saved_regs++ = next_addr;
  365.       next_addr += 4;
  366.     }
  367.  
  368.       cache_fsr->regs[FP_REGNUM] = cache_fsr->regs[PFP_REGNUM];
  369.     }
  370.  
  371.   *fsr = *fi->fsr;
  372.  
  373.   /* Fetch the value of the sp from memory every time, since it
  374.      is conceivable that it has changed since the cache was flushed.  
  375.      This unfortunately undoes much of the savings from caching the 
  376.      saved register values.  I suggest adding an argument to 
  377.      get_frame_saved_regs () specifying the register number we're
  378.      interested in (or -1 for all registers).  This would be passed
  379.      through to FRAME_FIND_SAVED_REGS (), permitting more efficient
  380.      computation of saved register addresses (e.g., on the i960,
  381.      we don't have to examine the prologue to find local registers). 
  382.     -- markf@wrs.com 
  383.      FIXME, we don't need to refetch this, since the cache is cleared
  384.      every time the child process is restarted.  If GDB itself
  385.      modifies SP, it has to clear the cache by hand (does it?).  -gnu */
  386.  
  387.   fsr->regs[SP_REGNUM] = read_memory_integer (fsr->regs[SP_REGNUM], 4);
  388. }
  389.  
  390. /* Return the address of the argument block for the frame
  391.    described by FI.  Returns 0 if the address is unknown.  */
  392.  
  393. CORE_ADDR
  394. frame_args_address (fi, must_be_correct)
  395.      struct frame_info *fi;
  396. {
  397.   register FRAME frame;
  398.   struct frame_saved_regs fsr;
  399.   CORE_ADDR ap;
  400.  
  401.   /* If g14 was saved in the frame by the function prologue code, return
  402.      the saved value.  If the frame is current and we are being sloppy,
  403.      return the value of g14.  Otherwise, return zero.  */
  404.  
  405.   frame = FRAME_INFO_ID (fi);
  406.   get_frame_saved_regs (fi, &fsr);
  407.   if (fsr.regs[G14_REGNUM])
  408.     ap = read_memory_integer (fsr.regs[G14_REGNUM],4);
  409.   else {
  410.     if (must_be_correct)
  411.       return 0;            /* Don't cache this result */
  412.     if (get_next_frame (frame))
  413.       ap = 0;
  414.     else
  415.       ap = read_register (G14_REGNUM);
  416.   }
  417.   fi->arg_pointer = ap;        /* Cache it for next time */
  418.   return ap;
  419. }
  420.  
  421. /* Return the address of the return struct for the frame
  422.    described by FI.  Returns 0 if the address is unknown.  */
  423.  
  424. CORE_ADDR
  425. frame_struct_result_address (fi)
  426.      struct frame_info *fi;
  427. {
  428.   register FRAME frame;
  429.   struct frame_saved_regs fsr;
  430.   CORE_ADDR ap;
  431.  
  432.   /* If the frame is non-current, check to see if g14 was saved in the
  433.      frame by the function prologue code; return the saved value if so,
  434.      zero otherwise.  If the frame is current, return the value of g14.
  435.  
  436.      FIXME, shouldn't this use the saved value as long as we are past
  437.      the function prologue, and only use the current value if we have
  438.      no saved value and are at TOS?   -- gnu@cygnus.com */
  439.  
  440.   frame = FRAME_INFO_ID (fi);
  441.   if (get_next_frame (frame)) {
  442.     get_frame_saved_regs (fi, &fsr);
  443.     if (fsr.regs[G13_REGNUM])
  444.       ap = read_memory_integer (fsr.regs[G13_REGNUM],4);
  445.     else
  446.       ap = 0;
  447.   } else {
  448.     ap = read_register (G13_REGNUM);
  449.   }
  450.   return ap;
  451. }
  452.  
  453. /* Return address to which the currently executing leafproc will return,
  454.    or 0 if ip is not in a leafproc (or if we can't tell if it is).
  455.   
  456.    Do this by finding the starting address of the routine in which ip lies.
  457.    If the instruction there is "mov g14, gx" (where x is in [0,7]), this
  458.    is a leafproc and the return address is in register gx.  Well, this is
  459.    true unless the return address points at a RET instruction in the current
  460.    procedure, which indicates that we have a 'dual entry' routine that
  461.    has been entered through the CALL entry point.  */
  462.  
  463. CORE_ADDR
  464. leafproc_return (ip)
  465.      CORE_ADDR ip;    /* ip from currently executing function    */
  466. {
  467.   int i;
  468.   register struct misc_function *mf;
  469.   char *p;
  470.   int dst;
  471.   unsigned int insn1, insn2;
  472.   CORE_ADDR return_addr;
  473.   char *index ();
  474.  
  475.   if ((i = find_pc_misc_function (ip)) >= 0)
  476.     {
  477.       mf = &misc_function_vector[i];
  478.       if ((p = index (mf->name, '.')) && !strcmp (p, ".lf"))
  479.     {
  480.       if (next_insn (mf->address, &insn1, &insn2)
  481.           && (insn1 & 0xff87ffff) == 0x5c80161e       /* mov g14, gx */
  482.           && (dst = REG_SRCDST (insn1)) <= G0_REGNUM + 7)
  483.         {
  484.           /* Get the return address.  If the "mov g14, gx" 
  485.          instruction hasn't been executed yet, read
  486.          the return address from g14; otherwise, read it
  487.          from the register into which g14 was moved.  */
  488.  
  489.           return_addr = read_register ((ip == mf->address)
  490.                            ? G14_REGNUM : dst);
  491.  
  492.           /* We know we are in a leaf procedure, but we don't know
  493.          whether the caller actually did a "bal" to the ".lf"
  494.          entry point, or a normal "call" to the non-leaf entry
  495.          point one instruction before.  In the latter case, the
  496.          return address will be the address of a "ret"
  497.          instruction within the procedure itself.  We test for
  498.          this below.  */
  499.  
  500.           if (!next_insn (return_addr, &insn1, &insn2)
  501.           || (insn1 & 0xff000000) != 0xa000000   /* ret */
  502.               || find_pc_misc_function (return_addr) != i)
  503.         return (return_addr);
  504.         }
  505.     }
  506.     }
  507.   
  508.   return (0);
  509. }
  510.  
  511. /* Immediately after a function call, return the saved pc.
  512.    Can't go through the frames for this because on some machines
  513.    the new frame is not set up until the new function executes
  514.    some instructions. 
  515.    On the i960, the frame *is* set up immediately after the call,
  516.    unless the function is a leaf procedure.  */
  517.  
  518. CORE_ADDR
  519. saved_pc_after_call (frame)
  520.      FRAME frame;
  521. {
  522.   CORE_ADDR saved_pc;
  523.   CORE_ADDR get_frame_pc ();
  524.  
  525.   saved_pc = leafproc_return (get_frame_pc (frame));
  526.   if (!saved_pc)
  527.     saved_pc = FRAME_SAVED_PC (frame);
  528.  
  529.   return (saved_pc);
  530. }
  531.  
  532. /* Discard from the stack the innermost frame,
  533.    restoring all saved registers.  */
  534.  
  535. pop_frame ()
  536. {
  537.   register struct frame_info *current_fi, *prev_fi;
  538.   register int i;
  539.   CORE_ADDR save_addr;
  540.   CORE_ADDR leaf_return_addr;
  541.   struct frame_saved_regs fsr;
  542.   char local_regs_buf[16 * 4];
  543.  
  544.   current_fi = get_frame_info (get_current_frame ());
  545.  
  546.   /* First, undo what the hardware does when we return.
  547.      If this is a non-leaf procedure, restore local registers from
  548.      the save area in the calling frame.  Otherwise, load the return
  549.      address obtained from leafproc_return () into the rip.  */
  550.  
  551.   leaf_return_addr = leafproc_return (current_fi->pc);
  552.   if (!leaf_return_addr)
  553.     {
  554.       /* Non-leaf procedure.  Restore local registers, incl IP.  */
  555.       prev_fi = get_frame_info (get_prev_frame (FRAME_INFO_ID (current_fi)));
  556.       read_memory (prev_fi->frame, local_regs_buf, sizeof (local_regs_buf));
  557.       write_register_bytes (REGISTER_BYTE (R0_REGNUM), local_regs_buf, 
  558.                     sizeof (local_regs_buf));
  559.  
  560.       /* Restore frame pointer.  */
  561.       write_register (FP_REGNUM, prev_fi->frame);
  562.     }
  563.   else
  564.     {
  565.       /* Leaf procedure.  Just restore the return address into the IP.  */
  566.       write_register (RIP_REGNUM, leaf_return_addr);
  567.     }
  568.  
  569.   /* Now restore any global regs that the current function had saved. */
  570.   get_frame_saved_regs (current_fi, &fsr);
  571.   for (i = G0_REGNUM; i < G14_REGNUM; i++)
  572.     {
  573.       if (save_addr = fsr.regs[i])
  574.     write_register (i, read_memory_integer (save_addr, 4));
  575.     }
  576.  
  577.   /* Flush the frame cache, create a frame for the new innermost frame,
  578.      and make it the current frame.  */
  579.  
  580.   flush_cached_frames ();
  581.   set_current_frame (create_new_frame (read_register (FP_REGNUM), read_pc ()));
  582. }
  583.  
  584. /* Print out text describing a "signal number" with which the i80960 halted.
  585.   
  586.    See the file "fault.c" in the nindy monitor source code for a list
  587.    of stop codes.  */
  588.  
  589. void
  590. print_fault( siggnal )
  591.     int siggnal;    /* Signal number, as returned by target_wait() */
  592. {
  593.     static char unknown[] = "Unknown fault or trace";
  594.     static char *sigmsgs[] = {
  595.         /* FAULTS */
  596.         "parallel fault",    /* 0x00 */
  597.         unknown,        /* 0x01 */
  598.         "operation fault",    /* 0x02 */
  599.         "arithmetic fault",    /* 0x03 */
  600.         "floating point fault",    /* 0x04 */
  601.         "constraint fault",    /* 0x05 */
  602.         "virtual memory fault",    /* 0x06 */
  603.         "protection fault",    /* 0x07 */
  604.         "machine fault",    /* 0x08 */
  605.         "structural fault",    /* 0x09 */
  606.         "type fault",        /* 0x0a */
  607.         "reserved (0xb) fault",    /* 0x0b */
  608.         "process fault",    /* 0x0c */
  609.         "descriptor fault",    /* 0x0d */
  610.         "event fault",        /* 0x0e */
  611.         "reserved (0xf) fault",    /* 0x0f */
  612.  
  613.         /* TRACES */
  614.         "single-step trace",    /* 0x10 */
  615.         "branch trace",        /* 0x11 */
  616.         "call trace",        /* 0x12 */
  617.         "return trace",        /* 0x13 */
  618.         "pre-return trace",    /* 0x14 */
  619.         "supervisor call trace",/* 0x15 */
  620.         "breakpoint trace",    /* 0x16 */
  621.     };
  622. #    define NUMMSGS ((int)( sizeof(sigmsgs) / sizeof(sigmsgs[0]) ))
  623.  
  624.     if (siggnal < NSIG) {
  625.           printf ("\nProgram received signal %d, %s\n",
  626.               siggnal,
  627.               sys_siglist[siggnal]);
  628.     } else {
  629.         /* The various target_wait()s bias the 80960 "signal number"
  630.            by adding NSIG to it, so it won't get confused with any
  631.            of the Unix signals elsewhere in GDB.  We need to
  632.            "unbias" it before using it.  */
  633.         siggnal -= NSIG;
  634.  
  635.         printf("Program stopped for reason #%d: %s.\n", siggnal,
  636.                 (siggnal < NUMMSGS && siggnal >= 0)?
  637.                 sigmsgs[siggnal] : unknown );
  638.     }
  639. }
  640.  
  641. /* Initialization stub */
  642.  
  643. _initialize_i960_tdep ()
  644. {
  645.   check_host ();
  646. }
  647.